home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / croutes.zip / MENCON.C < prev    next >
Text File  |  1980-01-01  |  7KB  |  231 lines

  1. /*                         *** mencon.c ***                          */
  2. /*                                                                   */
  3. /* IBM-PC microsoft "C" under PC-DOS v2.0                            */
  4. /*                                                                   */
  5. /* Function to open a menu file and display it on the screen.        */
  6. /* Returns the number of entry fields found on the menu (nfield) or  */
  7. /* -1 if an error occured.  Places the r,c coordinates of the entry  */
  8. /* fields within the globally declared rc array.                     */
  9. /*                                                                   */
  10. /* To build a menu, use the text editor to create a file called      */
  11. /* xxxx.mnu   This file contains the menu test as it should appear   */
  12. /* on the screen.  The screen is not automatically erased when menus */
  13. /* are displayed to allow for overlaying.  Command lines control the */
  14. /* various display parameters.  See \comm\comm.mnu for a menu text   */
  15. /* example and \comm\ibmtty.c for a menu call example.               */
  16. /*                                                                   */
  17. /* Command summary - column 1 contains a '>'.                        */
  18. /*                                                                   */
  19. /*>BE        - ring bell                                          */
  20. /*>CC        - comment line                                       */
  21. /*>DA rr cc    - display system date at given row and column        */
  22. /*>DS xx    - toggle given screen attribute                      */
  23. /*            0 = all attributes off                       */
  24. /*            1 = BOLD                                     */
  25. /*            4 = underscore                               */
  26. /*            5 = blink                                    */
  27. /*            7 = reverse video                            */
  28. /*            8 = invisible                                */
  29. /*>ES        - erase screen                                       */
  30. /*>EL xx    - erase xx number lines                              */
  31. /*>FR ulr ulc lrr lrc    - draw a box                                 */
  32. /*>PA xx.    - pause xx seconds (must be a real number)           */
  33. /*>RP min max    - set valid range of responses (used by chosit)      */
  34. /*>ST ll    - set line counter (start diplaying) to given line   */
  35. /*>SK xx    - increment line counter (skip) xx lines             */
  36. /*>SC c        - change default input marker from '[' to 'c'        */
  37. /*>TI rr cc    - display time at given row and column               */
  38. /*                                                                   */
  39. /* Written by L. Cuthbertson, March 1984.                            */
  40. /*                                                                   */
  41. /*********************************************************************/
  42. /*                                                                   */
  43.  
  44. #include <stdio.h>
  45.  
  46. #define NULL        '\000'
  47. #define COMKEY        '>'
  48. #define SPACE        ' '
  49. #define LBRACK        '['
  50.  
  51. int rc[50][2];
  52. int lenrc;
  53. int vrange[2];
  54.  
  55. int mencon(menu)
  56. char menu[];
  57. {
  58.     char line[81],menufile[30];
  59.     char inchar;
  60.     int irow,icol,nfield;
  61.     FILE *mfp;
  62.  
  63.     /* build menu file menu */
  64.     strcpy(menufile,menu);
  65.     strcat(menufile,".mnu");
  66.  
  67.     /* open file */
  68.     if ((mfp = fopen(menufile,"r")) == NULL) {
  69.         return(-1);
  70.     }
  71.  
  72.     /* read loop */
  73.     irow = 0;        /* line counter */
  74.     nfield = 0;        /* entry field counter */
  75.     inchar = LBRACK;    /* default input position marker */
  76.     while (getline(mfp,line,sizeof(line)) != EOF) {
  77.  
  78.         /* handle command lines */
  79.         if (line[0] == COMKEY) {
  80.             if (docomm(line,&irow,&inchar) == (-1)) {
  81.                 cursor(25,1);
  82.                 writes("\007*** invalid menu command ***");
  83.                 pause(2.);
  84.                 writes(line);
  85.                 pause(2.);
  86.             }
  87.             continue;
  88.         }
  89.  
  90.         /* got a menu line - bump up line counter */
  91.         irow++;
  92.  
  93.         /* check for blank line */
  94.         if (line[0] == NULL)
  95.             continue;
  96.  
  97.         /* locate start of actual information on line */
  98.         for (icol=1;line[icol-1] == SPACE;icol++)
  99.             ;
  100.         cursor(irow,icol);
  101.  
  102.         /* output information */
  103.         for (;line[icol-1] != NULL;icol++) {
  104.             writec(line[icol-1]);
  105.  
  106.             /* check for input position */
  107.             if (line[icol-1] == inchar) {
  108.                 nfield++;
  109.                 rc[lenrc][0] = irow;
  110.                 rc[lenrc++][1] = (icol+1);
  111.             }
  112.         }
  113.  
  114.     }
  115.  
  116.     /* done */
  117.     fclose(mfp);
  118.     return(nfield);
  119. }
  120.  
  121. /*********************************************************************/
  122. /*                                                                   */
  123. /*                        *** docomm.c ***                           */
  124. /*                                                                   */
  125. /* IBM - PC microsoft "C"                                            */
  126. /*                                                                   */
  127. /* Function to execute menu commands for the function mencon.        */
  128. /* Returns a 0 if successful or a -1 if not.                         */
  129. /*                                                                   */
  130. /*********************************************************************/
  131. /*                                                                   */
  132.  
  133. #include <ctype.h>
  134. #define BELL        '\007'
  135.  
  136. int docomm(line,icrow,inchar)
  137. char line[],*inchar;
  138. int *icrow;
  139. {
  140.     char command[2],date[9],time[9];
  141.     int i,irow,icol,irel;
  142.     int iatt,ulrow,ulcol,lrrow,lrcol;
  143.     float frel;
  144.  
  145.     /* get command */
  146.     command[0] = toupper(line[1]);
  147.     command[1] = toupper(line[2]);
  148.  
  149.     /* ring bell */
  150.     if (command[0] == 'B' && command[1] == 'E') {
  151.         sscanf(line,"%*4s%d",&irel);
  152.         for(i=0;i<irel;i++) {
  153.             writec(BELL);
  154.         }
  155.  
  156.     /* check for comment line */
  157.     } else if (command[0] == 'C' && command[1] == 'C') {
  158.         return (1);
  159.  
  160.     /* display date */
  161.     } else if (command[0] == 'D' && command[1] == 'A') {
  162.         sscanf(line,"%*4s%d%d",&irow,&icol);
  163.         cursor(irow,icol);
  164.         getdate(date);
  165.         writes(date);
  166.  
  167.     /* toggle screen attribute */
  168.     } else if (command[0] == 'D' && command[1] == 'S') {
  169.         sscanf(line,"%*4s%d",&iatt);
  170.         if (scratt(iatt) == (-1))
  171.             return(-1);
  172.  
  173.     /* erase screen */
  174.     } else if (command[0] == 'E' && command[1] == 'S') {
  175.         lenrc = 0;        /* initialize rc array */
  176.         escreen(2);
  177.  
  178.     /* erase x number of lines */
  179.     } else if (command[0] == 'E' && command[1] == 'L') {
  180.         sscanf(line,"%*4s%d%d",&irel,&icol);
  181.         for (i=0;i<irel;i++) {
  182.             cursor((*icrow+i+1),icol);
  183.             eline(0);
  184.         }
  185.         cursor(*icrow,1);
  186.  
  187.     /* frame */
  188.     } else if (command[0] == 'F' && command[1] == 'R') {
  189.         sscanf(line,"%*4s%d%d%d%d",&ulrow,&ulcol,&lrrow,&lrcol);
  190.         if (frame(ulrow,ulcol,lrrow,lrcol) == (-1))
  191.             return(-1);
  192.  
  193.     /* pause */
  194.     } else if (command[0] == 'P' && command[1] == 'A') {
  195.         sscanf(line,"%*4s%f",&frel);
  196.         pause(frel);
  197.  
  198.     /* set valid range */
  199.     } else if (command[0] == 'R' && command[1] == 'P') {
  200.         sscanf(line,"%*4s%d%d",&vrange[0],&vrange[1]);
  201.  
  202.     /* set line counter directly */
  203.     } else if (command[0] == 'S' && command[1] == 'T') {
  204.         sscanf(line,"%*4s%d",icrow);
  205.         *icrow -= 1;
  206.  
  207.     /* increment line counter directly */
  208.     } else if (command[0] == 'S' && command[1] == 'K') {
  209.         sscanf(line,"%*4s%d",&irel);
  210.         *icrow += irel;
  211.  
  212.     /* set input position marker */
  213.     } else if (command[0] == 'S' && command[1] == 'C') {
  214.         *inchar = line[4];
  215.  
  216.     /* display time */
  217.     } else if (command[0] == 'T' && command[1] == 'I') {
  218.         sscanf(line,"%*4s%d%d",&irow,&icol);
  219.         cursor(irow,icol);
  220.         gettime(time);
  221.         writes(time);
  222.  
  223.     /* error */
  224.     } else {
  225.         return (-1);
  226.     } 
  227.  
  228.     /* done */
  229.     return(0);
  230. }
  231.